package com.busApp;

import java.util.Set;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;

@SuppressWarnings("deprecation")
public class notificationPlugin extends Plugin{

	@Override
	public PluginResult execute(String action, JSONArray data, String callbackId) {
		Context context = cordova.getActivity().getApplicationContext();
		try {
			
			NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
			Notification mNotification = new Notification(R.drawable.ic_launcher, "到站提醒", System.currentTimeMillis());
            mNotification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;//设置图标自动清除或不可清除     
            Intent notificationIntent = new Intent(context, MyActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
            mNotification.setLatestEventInfo(context, data.getString(0), data.getString(1), pendingIntent);
            mNotification.flags|=Notification.FLAG_AUTO_CANCEL;  
            mNotification.defaults |= Notification.DEFAULT_SOUND;  
            

           mNotificationManager.notify(1,mNotification);  
			return new PluginResult(PluginResult.Status.OK, "");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new PluginResult(PluginResult.Status.ERROR, "");
		}
	}
	
}
